// 让便签可被拖动，但不能超出视口
var note = document.querySelector('.note');
var moveBar = document.querySelector('.move-bar');

moveBar.onmousedown = function (e) {
  var mouseStartDownX = e.clientX,
    mouseStartDownY = e.clientY;
  var noteStartLeft = note.offsetLeft,
    noteStartTop = note.offsetTop;

  window.onmousemove = function (e) {
    var mouseCurrentX = e.clientX,
      mouseCurrentY = e.clientY;
    var noteCurrentLeft = noteStartLeft + mouseCurrentX - mouseStartDownX,
      noteCurrentTop = noteStartTop + mouseCurrentY - mouseStartDownY;

    note.style.left = noteCurrentLeft + 'px';
    note.style.top = noteCurrentTop + 'px';
  };

  window.onmouseup = function (e) {
    console.log('鼠标松开');
    window.onmousemove = null;
    window.onmouseup = null;
  };
};
